package com.batchengine.test;

import static com.batchengine.Definitions.ContextParams.ARGUMENTS;
import static com.batchengine.Definitions.ContextParams.OWNER;
import com.batchengine.task.DefaultTask;
import com.batchengine.task.TaskContext;
import com.batchengine.task.TaskMode;
import static com.batchengine.task.TaskMode.READ;
import com.batchengine.util.LoggingFactory;
import com.batchengine.worker.Worker;
import org.apache.log4j.Logger;

/**
 * Created by  solutions
 * Author: sunil.incubator@yahoo.com
 * Date: Aug 5, 2009
 */
public class HelloWordTask extends DefaultTask {

    private static final Logger logger = LoggingFactory.createLogger();

    public HelloWordTask() {
        super("HelloWordTask");
    }

    protected HelloWordTask(String name) {
        super(name);
    }

    @Override
    public void execute(TaskContext context) {

        Object work = context.getContextParam(ARGUMENTS);
        Worker worker = (Worker) context.getContextParam(OWNER);
        if (null != work) {
            logger.debug(String.format("executing work  <== %s By %s", work, worker.getName()));
        }
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }

    @Override
    public TaskMode getTaskMode() {
        return READ;
    }
}
